package kr.co.hk.position;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.view.MotionEvent;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem> {

	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context mContext;
	public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		mContext = context;
	}


	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}
	
	public void clearList(){
		mOverlays.clear();populate();
	}

//	@Override
//	protected boolean onTap(int index) {
//		OverlayItem item = mOverlays.get(index);
//		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
//		dialog.setTitle(item.getTitle());
//		dialog.setMessage(item.getSnippet());
//		dialog.show();
//		return true;
//	}
	
	@Override
	public boolean onTap(GeoPoint p, MapView mapView) {
		String latlng ="lat" +(int)p.getLatitudeE6()/1E6 + "lng" +(int)p.getLongitudeE6()/1E6;
		SimulPosition.edText(latlng);
		
		this.hitLocation(p);
		return super.onTap(p, mapView);
	}
	
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		
		super.draw(canvas, mapView, shadow);
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event, MapView mapView) {
		System.out.println("event = "+event);
		return super.onTouchEvent(event, mapView);
	}
	
	
	
	
	public void hitLocation(GeoPoint p){
		
		Location currentLocation = new Location("HitLocation");
		currentLocation.setLatitude(p.getLatitudeE6());
		currentLocation.setLongitude(p.getLongitudeE6());
		
		GeoPoint point = new GeoPoint((int)currentLocation.getLatitude(), (int)currentLocation.getLongitude());
		
		OverlayItem overlayitem = new OverlayItem(point,
				"Title", "snippet");
		mOverlays = new ArrayList<OverlayItem>();
		this.addOverlay(overlayitem);
		
		
	}
}